package com.itboye.ihomebank.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.HouseDetailBean.OwnerInfo.OtherHouses;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;
import com.itboye.ihomebank.util.XImageLoader;

import static android.R.id.list;
import static com.alibaba.mobileim.YWChannel.getResources;
import static com.itboye.ihomebank.R.id.home_danjia;

/***
 * 示例adapter
 *
 * @author mr.w
 */
public class JinJiRenOtherHouseAdapter extends
        MutiplyCommonAdapter<OtherHouses> {
    int position;

    public JinJiRenOtherHouseAdapter(Context context, List<OtherHouses> datas,
                                     int... layoutId) {
        super(context, datas, layoutId);
        // TODO Auto-generated constructor stub
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub

        return 0;
    }

    @Override
    public void convert(ViewHolder holder, OtherHouses t, int type,
                        final int position) {
        XImageLoader.load(NetPublicConstant.IMAGE_URL + t.getMainImg(),
                (ImageView) holder.getView(R.id.home_adapter));
        holder.setText(R.id.home_title,
                t.getRentType() + "·" + t.getCommunity() + t.getHouseHall()
                        + "室/" + t.getHouseRoom() + "厅/" + t.getToilet() + "卫");

        holder.setText(R.id.home_xq, Html.fromHtml(t.getHouseArea() + "㎡·"
                + t.getOrientation()));
        holder.setText(R.id.home_money,t.getArea()+"-"+t.getAreaZone());
        holder.setText(R.id.danjia, (Double.parseDouble(t.getRent())) / 100+ "元/月");

        holder.setVisible(R.id.home_danjia,false);

        String str[] = null;
        ((LinearLayout) holder.getView(R.id.tag)).removeAllViews();
        if (t.getTagNames() != null) {

            if (t.getTagNames().equals("")) {
                holder.setVisible(R.id.tag, false);
            } else if (t.getTagNames().contains(",")) {
                str = t.getTagNames().split(",");
                for (int i = 0; i < str.length; i++) {
                    View innerView = LayoutInflater.from(MyApplcation.ctx)
                            .inflate(R.layout.item_biaoqian, null);
                    TextView btn_name = (TextView) innerView
                            .findViewById(R.id.btn_name);
                    btn_name.setText(str[i]);
                    LayoutParams layoutParams = new LayoutParams(
                            LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT);
                    layoutParams.setMargins(5, 5, 5, 5);
                    innerView.setLayoutParams(layoutParams);
                    ((LinearLayout) holder.getView(R.id.tag))
                            .addView(innerView);
                }

            } else {
                View innerView = LayoutInflater.from(MyApplcation.ctx).inflate(
                        R.layout.item_biaoqian, null);
                TextView btn_name = (TextView) innerView
                        .findViewById(R.id.btn_name);
                btn_name.setText(t.getTagNames());
                MarginLayoutParams layoutParams = new MarginLayoutParams(
                        MarginLayoutParams.WRAP_CONTENT,
                        MarginLayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(5, 5, 5, 5);
                innerView.setLayoutParams(layoutParams);
                ((LinearLayout) holder.getView(R.id.tag)).addView(innerView);
            }
        }
    }

    @Override
    public void getItemPosition(int position) {
        // TODO Auto-generated method stub
        this.position = position;
    }

}
